/*
* Copyright 2009 NOR_/D Labs <http://labs.nortd.com>
*
* This file is part of SceneExpression.
* SceneExpression is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License 
* as published by the Free Software Foundation, either version 3 of 
* the License, or (at your option) any later version. For details
* see <http://www.gnu.org/licenses/>.
*
* * *
* 
*/


#include "sxPanelWidget.h"

  
sxPanelWidget::sxPanelWidget() {
    
    // label
    _label = new  osgText::Text;
    _geode->addDrawable( _label.get() );
    _defaultTypeface = sxDataPathRoot + "TitilliumText400wt.ttf";
    _label->setAlignment(osgText::Text::CENTER_CENTER);
    
    setPosition(0.0f, 0.0f, 0.0f);
    setShape(100, 25);
    
}


void sxPanelWidget::reshape() {
    // define geometry
    _backgroundVertices->clear();
    setBackgroundColor(0.0f, 0.0f, 0.0f, 0.4f);
    addRoundedRect(0.0f, 0.0f, _width, _height, 8.f, _backgroundVertices.get());
    _backgroundDrawArray->setCount(_backgroundVertices->size());
    //setPivot(width/2.f, height/2.f, 0.f);
    //setBorderColor(0.0f, 0.0f, 0.0f, 0.4f);
    //borderDrawArray->setCount(backgroundVertices->size());
    
    //label
    float labelHeight = 20.0f;
    setLabelColor(0.5f, 0.5f, 0.5f, 1.f);
    _label->setFont(_defaultTypeface);
    _label->setText(getName());
    _label->setPosition(osg::Vec3(_width/2.0f, _height-0.5*labelHeight-0.2*labelHeight, 0.0f));
    _label->setCharacterSize(labelHeight);
    _label->setMaximumWidth(_width);
    _label->setMaximumHeight(_height);
}

void sxPanelWidget::setLabelColor( float r, float g, float b, float a ) {
    _label->setColor(osg::Vec4(r,g,b,a));
}



// Frame Events
//
void sxPanelWidget::update() {
    /*
    if( velocity[0] > 0.00001 || velocity[1] > 0.00001 || velocity[2] > 0.00001 ) {
        velocity = velocity * 0.8;
        //addPosition(velocity);
    } else {
        velocity.set(0,0,0);
    }
    */
    
    //static float ang = 0.0f;
    //addZ(1);
    //addRotationX(3.14/200);
}



// Touch Events
//
bool sxPanelWidget::touchDown( sxTouch& touch ) {
    //enableDragging( touch );
    return true;
}  
bool sxPanelWidget::touchMove( sxTouch& touch ) {
    if( isDragging(touch) ) {
        addPosition(getWorldVelocity(touch));
    }
    return true;
}
bool sxPanelWidget::touchUp( sxTouch& touch ) {
    //disableDragging( touch );
    return true;
}

